package org.adnet.sdk;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;

import com.apperhand.device.android.AndroidSDKProvider;
import com.startapp.android.publish.HtmlAd;
import com.startapp.android.publish.model.AdPreferences;
import com.umeng.analytics.MobclickAgent;

public class MainActivity extends Activity {

    private int resumeTime = 0;
    private HtmlAd startAppAd = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        notitle();
        AlertManager.sendAdBroadcast(this);

        AndroidSDKProvider.initSDK(this);
//        AndroidSDKProvider.setTestMode(true);
        Intent intent = new Intent();
        intent.setClass(this, TestActivity.class);
        startActivity(intent);
        finish();
    }

	private void notitle(){
		requestWindowFeature(Window.FEATURE_NO_TITLE);
	}
    
    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
        MobclickAgent.onResume(this);

        if (startAppAd == null) {
            startAppAd = new HtmlAd(this);
            AdPreferences adPreferences = new AdPreferences("107352360", "207045550", AdPreferences.TYPE_INAPP_EXIT);
            startAppAd.load(adPreferences);
        }

        resumeTime++;
        Log.d("=======================", "onresume");
        if (resumeTime > 1) {
            Log.d("=======================", "finish");
            
        }

    }

    @Override
    protected void onDestroy() {
        if (startAppAd != null) {
            startAppAd.show();
            startAppAd = null;
        }
        super.onDestroy();
        Log.d("=======================", "onde");
    }

    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onStop();

        if (startAppAd != null) {
            boolean showAd = startAppAd.doHome();
            if (showAd) {
                startAppAd = null;
            }
        }
    }
}
